{template '_header'}
 

<div class="page-heading"> 
	
	<span class='pull-right'>
		
		{ifp 'tmessage.add'}
                            <a class="btn btn-primary btn-sm" href="{php echo webUrl('tmessage/add')}">添加新幻灯片</a>
		{/if}
                
		<a class="btn btn-default  btn-sm" href="{php echo webUrl('tmessage')}">返回列表</a>
                
                <a class='btn btn-warning btn-sm' data-toggle='popover' href="javascript:;" data-placement='bottom' data-html='true'
                   data-content="如模板详情为: <br/><br/> {{first.DATA}}<br/>
                            订单金额：{{keyword1.DATA}}<br/>
商品详情：{{keyword2.DATA}}<br/>
收货信息：{{keyword3.DATA}}<br/>
{{remark.DATA}}<br/><br/>

<b>头部标题</b>：{{keyword1.DATA}}<br/>
<b>键名</b>：keyword1/keyword2 <br/><b>键值</b>： 您要设置的模板项的值<br/>
<b>尾部描述</b>：{{remark.DATA}}<br/>
">
                    <i class='fa fa-question-circle'></i> 简易帮助
                </a>
	</span>
	<h2>{if !empty($item['id'])}编辑{else}添加{/if}群发模板 <small>{if !empty($item['id'])}修改【{$item['title']}】{/if}</small></h2> 
</div>



<div class="main">
    <form {ife 'tmessage' $list}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
 
                
                <input type="hidden" name="tp_id" value="{$list['id']}" />
                
                <div class="form-group">
                    <label class="col-sm-2 control-label must" >模板名称</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'tmessage' $list}
                        <input type="text" name="tp_title" class="form-control" value="{$list['title']}" placeholder="模版名称，例：新品上市通知群发（自定义）" data-rule-required='true' />
                        {else}
                        <div class='form-control-static'>{$list['title']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label must" >模板消息ID</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'tmessage' $list}
                        <input type="text" name="tp_template_id" class="form-control" value="{$list['template_id']}" placeholder="模版消息ID，例：P8MxRKmW7wdejmZl14-swiGmsJVrFJiWYM7zKSPXq4I" data-rule-required='true' />
                             {else}
                        <div class='form-control-static'>{$list['template_id']}</div>
                        {/if}
                    </div> 
                </div> 
                <div class="form-group">
                    <label class="col-sm-2 control-label must" >头部标题</label>  
                    
                    {ife 'tmessage' $list}
                    <div class="col-sm-5 title" style='padding-right:0' >
                            
                        <input type="text" name="tp_first" class="form-control" value="{$list['first']}" data-rule-required='true' data-parent='title' placeholder="{{first.DATA}}"/>
                        <span class='help-block'>对填充模板 {{first.DATA}} 的值 </span>
                    </div>
                       <div class="col-sm-5" style='padding-left:0;' >
                          
                           {php echo tpl_form_field_color('firstcolor', $list['firstcolor'])}
                        
                    </div>
                       {else}
                       <div class="col-sm-3">
                             <div class='form-control-static'>{$list['first']} 颜色: {$list['firstcolor']}</div>
                             </div>
                        {/if}
                        
                </div>
                  
                {loop $data $list2}
                    {template 'tmessage/tpl'}
                {/loop}
                  {ife 'tmessage' $list}
                <div id="type-items"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" ></label>
                    <div class="col-sm-9 col-xs-12">
                        <a class="btn btn-default btn-add-type" href="javascript:;" onclick="addType();"><i class="fa fa-plus" title=""></i> 增加一条键</a>
                        <span class='help-block'>
                        
                        </span>
                    </div>
                </div>
                {/if}
                
                <div class="form-group">
                    <label class="col-sm-2 control-label" >尾部描述</label>
                       {ife 'tmessage' $list}
                     <div class="col-sm-5 title" style='padding-right:0' >
                        <input type="text" name="tp_remark" class="form-control" value="{$list['remark']}" placeholder="{{remark.DATA}}" />
                      <span class='help-block'>填充模板 {{remark.DATA}} 的值 </span>
                    </div>
                    <div class="col-sm-5 title" style='padding-left:0' >
                           {php echo tpl_form_field_color('remarkcolor', $list['remarkcolor'])}
                    </div>
                    
                        {else}
                      <div class="col-sm-3">
                             <div class='form-control-static'>{$list['remark']} 颜色: {$list['remarkcolor']}</div>
                             </div>
                        {/if}
                        
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" >消息链接</label>
                    <div class="col-sm-9 col-xs-12">
                           {ife 'tmessage' $list}
                        <input type="text" name="tp_url" class="form-control" value="{$list['url']}" placeholder="" />
                        {else}
                        <div class='form-control-static'>{$list['url']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group"></div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label" ></label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'tmessage' $list}
                       <input type="submit"  value="提交" class="btn btn-primary"  />
	       
                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'tmessage.add|tmessage.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
                </div>
                
            </div>
 
     
 
<script language='javascript'>
    var kw = 1;
    function addType() {
        $(".btn-add-type").button("loading");
        $.ajax({ 
            url: "{php echo webUrl('tmessage/tpl')}&kw="+kw,
            cache: false
        }).done(function (html) {
            $(".btn-add-type").button("reset");
            $("#type-items").append(html);
        });
        kw++;
    }
 
        $('form').submit(function(){
      
            if($('.key_item').length<=0){
                tip.msgbox.err('请添加一条键!');
                $('form').attr('stop',1);
                return false;
            }
            var checkkw = true;
            $(":input[name='tp_kw[]']").each(function(){
                if ( $.trim( $(this).val() ) ==''){ 
                    checkkw = false;
                    tip.msgbox.err('请输入键名!');
                    $(this).focus();
                    $('form').attr('stop',1);
                    return false;
                }
            });
            if( !checkkw){
                return false;
            }
            $('form').removeAttr('stop');
            return true;
      });
 
    </script>

{template '_footer'}
